package co.com.web;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import co.com.ejb.WineSearchLocal;

/**
 * Servlet implementation class Servlet
 */
@WebServlet("/Servlet")
public class Servlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	
	@EJB
	WineSearchLocal bean;
	
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Servlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		bean.asyncHello("Maria");
		Future<String> future = bean.asyncFutureHello("Pedro");
		try {
			while (!future.isDone()) {
				Thread.sleep(1000);
				System.out.println("Future done? " + future.isDone());
			}
			System.out.println(future.get());
		} catch (InterruptedException | ExecutionException e) {}
		resp.getWriter().println(bean.sayHello("Juana"));
	}
}